package com.example.hemin.fnb.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.hemin.fnb.R;
import com.example.hemin.fnb.ui.activity.ShoppingCar;
import com.example.hemin.fnb.ui.activity.ShoppingCarItemActivity;
import com.example.hemin.fnb.ui.adapter.ShopAdapter;
import com.example.hemin.fnb.ui.adapter.ShopAdapters;
import com.example.hemin.fnb.ui.base.BaseMvpFragment;
import com.example.hemin.fnb.ui.bean.ShopBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class TabShopFragment extends BaseMvpFragment {


    Unbinder unbinder;
    @BindView(R.id.message_add)
    ImageView messageAdd;
    @BindView(R.id.shop_recyclerview)
    RecyclerView shopRecyclerview;
    private List<ShopBean> beans = new ArrayList<>();
    private ShopAdapter adapter = new ShopAdapter(R.layout.shop_activity,beans);


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_tab_shop;
    }

    @Override
    protected void initView(View view) {
        initDate();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        shopRecyclerview.setLayoutManager(linearLayoutManager);
        linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
         adapter = new ShopAdapter(R.layout.shop_activity, beans);
        shopRecyclerview.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(getActivity(), ShoppingCarItemActivity.class);
                 startActivity(intent);
            }
        });
    }

    @Override
    public void lazyInitView(View view) {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    private void initDate() {
        for (int i = 0; i < 5; i++) {

            ShopBean shopBean1 = new ShopBean("https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=tup&hs=2&pn=0&spn=0&di=142450&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=4135477902%2C3355939884&os=3635151272%2C707819180&simid=4013473509%2C415514012&adpicid=0&lpn=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=tup&objurl=http%3A%2F%2Fac-r.static.booking.cn%2Fimages%2Fhotel%2Fmax1024x768%2F987%2F98767654.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bk55htg2_z%26e3Bv54AzdH3Fi5pjsAzdH3FruAzdH3Frjgft5g-p7r7gw_z%26e3Bzi-vg_z%26e3Bip4s%3F_z%26e3Bzi-vg_z%26e3Bip4s&gsm=0&islist=&querylist=",
                    "09/20", "3000", 1, "1");
            ShopBean shopBean2 = new ShopBean("https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=tup&hs=2&pn=0&spn=0&di=142450&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=4135477902%2C3355939884&os=3635151272%2C707819180&simid=4013473509%2C415514012&adpicid=0&lpn=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=tup&objurl=http%3A%2F%2Fac-r.static.booking.cn%2Fimages%2Fhotel%2Fmax1024x768%2F987%2F98767654.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bk55htg2_z%26e3Bv54AzdH3Fi5pjsAzdH3FruAzdH3Frjgft5g-p7r7gw_z%26e3Bzi-vg_z%26e3Bip4s%3F_z%26e3Bzi-vg_z%26e3Bip4s&gsm=0&islist=&querylist=",
                    "09/20", "3000", 5, "1");
            ShopBean shopBean3 = new ShopBean("https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=tup&hs=2&pn=0&spn=0&di=142450&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&ie=utf-8&oe=utf-8&cl=2&lm=-1&cs=4135477902%2C3355939884&os=3635151272%2C707819180&simid=4013473509%2C415514012&adpicid=0&lpn=0&ln=30&fr=ala&fm=&sme=&cg=&bdtype=0&oriquery=tup&objurl=http%3A%2F%2Fac-r.static.booking.cn%2Fimages%2Fhotel%2Fmax1024x768%2F987%2F98767654.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bk55htg2_z%26e3Bv54AzdH3Fi5pjsAzdH3FruAzdH3Frjgft5g-p7r7gw_z%26e3Bzi-vg_z%26e3Bip4s%3F_z%26e3Bzi-vg_z%26e3Bip4s&gsm=0&islist=&querylist=",
                    "09/20", "3000", 0, "1");
            beans.add(shopBean1);
            beans.add(shopBean2);
            beans.add(shopBean3);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @OnClick({R.id.message_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.message_add:
                Intent intent = new Intent(getActivity(), ShoppingCar.class);
                startActivity(intent);
                break;

        }
    }
}
